package org.gpp.proj1.robot.action.step;

import java.util.List;
import java.util.Set;

import org.gpp.proj1.robot.Robot;
import org.gpp.proj1.robot.part.EquippedPart;
import org.gpp.proj1.robot.part.emissor.Emissor;

import com.jme.scene.Node;

/**
 * @author Paolo Victor, paolovictor@gmail.com
 */
public class StopEmissionActionStep implements ActionStep {
	
	private String emissorName;
	
	public StopEmissionActionStep( String emissorName ) {
		this.emissorName = emissorName;
	}

	/* (non-Javadoc)
	 * @see org.gpp.proj1.robot.action.step.ActionStep#execute(org.gpp.proj1.robot.part.EquippedPart, java.util.List)
	 */
	public void execute( EquippedPart parent, List<Robot> targets ) {
		this.execute( parent );
	}
	
	/* (non-Javadoc)
	 * @see org.gpp.proj1.robot.action.step.ActionStep#execute(org.gpp.proj1.robot.part.EquippedPart)
	 */
	public void execute( EquippedPart parent ) {
		Emissor emissor = parent.getEmissor( emissorName );
		Set<String> bones = parent.getAssignedBoneGroupNames();

		// For each bone on the emissor parent list, attach it to the bone
		// and start the particle emission
		for( String boneName : bones ) {
			Node emissorNode = emissor.getEmissorNode( boneName );
			
			if( emissorNode != null ) {
				parent.getParentRobot().removeEmissor( boneName, emissor );
				emissorNode.detachAllChildren();
			}
		}		
	}
	
	public String getEmissorName() {
		return emissorName;
	}
}